define(['util'], function (Util) {
    function ViewModel(params) {
        var scope = this;

        scope.pages = [];
        var storagePeriodDics = Util.ajaxGetSync({url:Util.getRestUrl('/dics'),data:{type:'保管期'}});

        for(var i=0;i<params.data.length;++i){
            if(params.data[i].childs) {
                for (var j = 0; j < params.data[i].childs.length; ++j) {


                    if (j % 18 == 0) {
                        scope.pages.push(Array.factory.initWithSame({value: '', count: 18}));
                    }

                    var storagePeriodDic = storagePeriodDics.data.findItemByField({
                        name: 'value',
                        value: params.data[i].childs[j].storagePeriod
                    });

                    var pageT = 0;

                    if(params.changePage) {
                        if(j == 0) {
                            pageT = 1;
                        }
                        else {
                            pageT = params.data[i].childs[j-1]['pageT'] + params.data[i].childs[j - 1].page;
                        }

                        if(j == params.data[i].childs.length - 1){
                            pageT = '{0}-{1}'.formatTpl(pageT,pageT + params.data[i].childs[j].page)
                        }
                    }
                    else {
                        pageT = params.data[i].childs[j].page
                    }

                    params.data[i].childs[j]['rowId'] = j + 1;
                    params.data[i].childs[j]['storagePeriodT'] = storagePeriodDic ? storagePeriodDic.text : '';
                    params.data[i].childs[j]['pageT'] = pageT;
                    scope.pages[scope.pages.length - 1][j % 18] = params.data[i].childs[j];
                }
            }
        }
    }

    return ViewModel;
});
